<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="lay/layui/css/layui.css" media="all" rel="stylesheet">
    <script charset="utf-8" src="lay/layui/layui.js"></script>
    <script src="js/jquery-3.3.1.min.js" type="text/javascript"></script>
</head>
<body class="layui-layout-body">
<div class="layui-container" style="margin-top: 50px;width: 720px;">
    <form action="" class="layui-form" method="POST">
        <div class="layui-form-item" style="margin-left: 50px;">
            <label class="layui-form-label">条件</label>
            <div class="layui-inline" style="width: 200px;">
                <input class="layui-input" name="index" placeholder="请输入试卷名称" type="text">
            </div>
            <div class="layui-inline" style="width: 200px;">
                <button class="layui-btn" lay-filter="find" lay-submit>搜索</button>
            </div>
        </div>

    </form>
    <table class="layui-table" id="test" lay-filter="test"></table>
    <script id="barDemo1" type="text/html">
        <a class="layui-btn layui-btn-xs" lay-event="grades">成绩列表</a>
    </script>
    <script charset="utf-8" src="layui/layui.js"></script>
    <script>
        layui.use(['form', 'table'], function () {
            var form = layui.form;
            var table = layui.table;
            form.on('submit(find)', function (data) {
                //获取 class_id 和 course_nam
                var index = data.field.index;
                var teacher = sessionStorage.getItem("id");
                if (index.length === 0) {
                    index = "null";
                }
                table.reload('test', {
                    url: '/question/test/getEndTest/'+teacher
                    , where: {
                        index: index
                    } //设定异步数据接口的额外参数
                    //,height: 300
                });
                return false;
            });
        });
        layui.use(['table', 'transfer', 'layer', 'util', 'form', 'laydate'], function () {
            var table = layui.table;
            var transfer = layui.transfer;
            var layer = layui.layer;
            var util = layui.util;
            var form = layui.form;
            var laydate = layui.laydate;
            table.render({
                elem: '#test'
                , url: '/question/test/getEndTest/' + sessionStorage.getItem("id")
                ,where: {
                    index:"null"
                }
                , title: '学生列表'
                , cols: [
                    [
                        {field: 'test_id', width: 100, title: '试卷编号', sort: true}
                        , {field: 'test_name', width: 100, title: '试卷名称'}
                        , {field: 'test_begin_time', width: 180, title: '开始时间'}
                        , {field: 'test_end_time', width: 180, title: '结束时间'}
                        , {fixed: 'right', title: '操作', toolbar: '#barDemo1', width: 120}
                    ]
                ]
                , page: false
            });

            //监听行工具事件
            table.on('tool(test)', function (obj) {
                var data = obj.data;
                if (obj.event === 'grades') {
                    window.open("/question/test/getGradesList/"+data.test_id, "_blank");
                }
            });
        });
    </script>
</div>
<script>
    //二级菜单联动
    layui.use('element', function () {
        var element = layui.element;

    });
</script>
</body>
</html>